package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.BreedReportManager;
import com.jiantong.work.model.BreedReport;
import com.jiantong.work.service.BreedReportWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by niufei on 2017/3/15.
 *
 */
@Slf4j
@Service
@RpcProvider
public class BreedReportWriteServiceImpl implements BreedReportWriteService{

    private final BreedReportManager breedReportManager;

    @Autowired
    public BreedReportWriteServiceImpl(BreedReportManager breedReportManager){
        this.breedReportManager = breedReportManager;
    }

    @Override
    public Response<Map<String , Object>> create(BreedReport breedReport , Integer toStatus) {
        try{
            return Response.ok(breedReportManager.createBreedReport(breedReport,toStatus));
        }catch (Exception e){
            log.error("failed to create breed report error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("breed.report.create.failed");
        }
    }

    @Override
    public Response<Map<String , Object>> update(BreedReport breedReport , Integer toStatus) {
        try{
            return Response.ok(breedReportManager.updateBreedReport(breedReport, toStatus));
        }catch (Exception e){
            log.error("failed to update breed report error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("update.failed");
        }
    }

    @Override
    public Boolean update(BreedReport breedReport) {

        return breedReportManager.update(breedReport);
    }
}
